package com.itheima.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * 保证一个web项目只有一个工厂
 * @author Johnny.Chen
 *
 */
public class JpaUtil {
	//全局变量
	private static EntityManagerFactory factory;
	
	static {
		factory = Persistence.createEntityManagerFactory("myJpa");
	}
	
	/**
	 * 使用这个方法获取实体类管理器
	 * @return
	 */
	public static EntityManager getEntityManager() {
		return factory.createEntityManager();
	}
	

}
